﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GalaSoft.MvvmLight;
using ALiteTeam.PackageTracer.Data;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using System.Windows;
using ALiteTeam.PackageTracer.Core;

namespace ALiteTeam.PackageTracer.ViewModel
{
    public class PriorityDelivery : ViewModelBase
    {
        public PriorityDelivery(Delivery delivery)
        {
            if (IsInDesignMode)
            {
            }
            else
            {
                this.DeliveryID = delivery.ID;
                this.Name = delivery.DisplayName;

                this.NavigationToInputCommand = new RelayCommand<Guid>(NavigationToInput);
            }
        }

        /// <summary>
        /// The <see cref="DeliveryID" /> property's name.
        /// </summary>
        public const string DeliveryIDPropertyName = "DeliveryID";
        private Guid mDeliveryID;

        /// <summary>
        /// Gets the DeliveryID property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public Guid DeliveryID
        {
            get
            {
                return mDeliveryID;
            }

            set
            {
                if (mDeliveryID == value)
                {
                    return;
                }
                mDeliveryID = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(DeliveryIDPropertyName);
            }
        }

        /// <summary>
        /// The <see cref="Name" /> property's name.
        /// </summary>
        public const string NamePropertyName = "Name";
        private string mName = string.Empty;

        /// <summary>
        /// Gets the Name property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public string Name
        {
            get
            {
                return mName;
            }

            set
            {
                if (mName == value)
                {
                    return;
                }

                mName = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(NamePropertyName);
            }
        }

        public RelayCommand<Guid> NavigationToInputCommand { get; private set; }
        private void NavigationToInput(Guid deliveryID)
        {
            Messenger.Default.Send<Guid>(deliveryID, InputOrderViewModel.INITIALIZE);
            (Application.Current.RootVisual as Microsoft.Phone.Controls.PhoneApplicationFrame).Navigate(new Uri("/View/InputOrder.xaml", UriKind.Relative));
        }
    }
}
